<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>注册系统</title>
    <meta name="description" content="">
    <!-- 360浏览器急速模式 -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>
    <link href="../static/css/bootstrap5.min.css" th:href="@{/css/bootstrap5.min.css}" rel="stylesheet"/>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
        <a class="navbar-brand" href="/stock/getAverageHoldingPercentage">首页</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse justify-content-end" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" aria-current="page" href="/stock/news">每日资讯</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" aria-current="page" href="/chat">AI问题解答</a>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h1 class="text-center">注册系统</h1>
                    <p class="text-center">请输入您的账号信息注册</p>
                </div>
                <div class="card-body">
                    <form id="registerForm" autocomplete="off">
                        <div class="mb-3">
                            <label class="form-label" for="userName">用户名</label>
                            <input id="userName" type="text" name="userName" class="form-control" placeholder="用户名" value=""/>
                        </div>
                        <div class="mb-3">
                            <label class="form-label" for="password">密码</label>
                            <input id="password" type="password" name="password" class="form-control" placeholder="密码" value=""/>
                        </div>
                        <div class="mb-3">
                            <label class="form-label" for="confirmPassword">确认密码</label>
                            <input id="confirmPassword" type="password" name="confirmPassword" class="form-control" placeholder="确认密码"
                                   value=""/>
                        </div>
                        <div class="d-grid mb-3">
                            <button class="btn btn-primary" id="btnSubmit" data-loading="正在验证注册，请稍候...">注册</button>
                        </div>
                        <div class="text-center">
                            <p>已有账号？<a href="/login.html">立即登录</a></p>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap5.min.js}"></script>
<script>
    $(document).ready(function () {
        $('#registerForm').on('submit', function (event) {
            event.preventDefault(); // 阻止默认表单提交行为

            var username = $('[name="userName"]').val();
            var password = $('[name="password"]').val();
            var confirmPassword = $('[name="confirmPassword"]').val();
            var rememberMe = $('#rememberMe').is(':checked');
            console.log(username, password, confirmPassword, rememberMe);
            // 检查密码和确认密码是否一致
            if (password !== confirmPassword) {
                alert('密码和确认密码不一致');
                return;
            }

            // 发送AJAX请求
            $.ajax({
                url: 'registerWithoutCaptcha',
                type: 'POST',
                data: {
                    loginName: username,
                    password: password,
                    rememberMe: rememberMe
                },
                success: function (response) {
                    if (response.code === 0) {
                        // 注册成功，显示提示信息并跳转到注册成功页面
                        alert('注册成功');
                        window.location.href = '/user/registerSuccess';
                    } else {
                        // 注册失败，显示错误信息
                        alert(response.msg);
                    }
                },
                error: function (xhr, status, error) {
                    // 处理请求错误
                    alert('注册请求失败，请稍后再试');
                }
            });
        });
    });
</script>
</body>
</html>
